package com.yuesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuesystem.entity.Feedback;
import com.yuesystem.mapper.FeedbackMapper;
import com.yuesystem.service.FeedbackService;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


/**
 * 反馈接口实现类.
 */
@Slf4j
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback>
    implements FeedbackService {
  public static Long userId = null;
  
  public static Long getUserId() {
    return FeedbackServiceImpl.userId;
  }
  
  public static void setUserId(Long userId) {
    FeedbackServiceImpl.userId = userId;
  }
  
  
  
  /**
   * 客服获取未处理的反馈.
   */
  @Override
  public Page<Feedback> getPage(int page, int pageSize) {
    Page<Feedback> dtoPage = new Page<>(page, pageSize);
    
    // 获取当前用户id
    Long currentId = FeedbackServiceImpl.getUserId();
    
    LambdaQueryWrapper<Feedback> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Feedback::getServiceId, currentId);
    queryWrapper.eq(Feedback::getStatus1, 0);
    List<Feedback> feedbacksList = this.list(queryWrapper);
    
    if (feedbacksList.size() == 0 || feedbacksList == null) {
      return dtoPage;
    }
    
    dtoPage.setRecords(feedbacksList);
    dtoPage.setTotal(feedbacksList.size());
    return dtoPage;
  }
  
  /**
   * 管理员、编辑获取反馈.
   *
   */
  @Override
  public Page<Feedback> getPage1(int page, int pageSize) {
    Page<Feedback> dtoPage = new Page<>(page, pageSize);
    
    // 获取当前用户id
    Long currentId = FeedbackServiceImpl.getUserId();
    
    LambdaQueryWrapper<Feedback> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Feedback::getDealId, currentId);
    queryWrapper.eq(Feedback::getStatus1, 1);
    queryWrapper.eq(Feedback::getStatus2, 0);
    List<Feedback> feedbacksList = this.list(queryWrapper);
    
    if (feedbacksList.size() == 0 || feedbacksList == null) {
      return dtoPage;
    }
    
    dtoPage.setRecords(feedbacksList);
    dtoPage.setTotal(feedbacksList.size());
    return dtoPage;
  }
  
  /**
   * 客服获取已处理的反馈.
   *
   */
  @Override
  public Page<Feedback> getPage2(int page, int pageSize) {
    Page<Feedback> dtoPage = new Page<>(page, pageSize);
    
    // 获取当前用户id
    Long currentId = FeedbackServiceImpl.getUserId();
    
    LambdaQueryWrapper<Feedback> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Feedback::getServiceId, currentId);
    queryWrapper.eq(Feedback::getStatus1, 1);
    List<Feedback> feedbacksList = this.list(queryWrapper);
    
    if (feedbacksList.size() == 0 || feedbacksList == null) {
      return dtoPage;
    }
    
    dtoPage.setRecords(feedbacksList);
    dtoPage.setTotal(feedbacksList.size());
    return dtoPage;
  }
  
  /**
   * 管理员、编辑获取已处理的反馈.
   *
   */
  @Override
  public Page<Feedback> getPage3(int page, int pageSize) {
    Page<Feedback> dtoPage = new Page<>(page, pageSize);
    
    // 获取当前用户id
    Long currentId = FeedbackServiceImpl.getUserId();
    
    LambdaQueryWrapper<Feedback> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Feedback::getDealId, currentId);
    queryWrapper.eq(Feedback::getStatus1, 1);
    queryWrapper.eq(Feedback::getStatus2, 1);
    List<Feedback> feedbacksList = this.list(queryWrapper);
    
    if (feedbacksList.size() == 0 || feedbacksList == null) {
      return dtoPage;
    }
    
    dtoPage.setRecords(feedbacksList);
    dtoPage.setTotal(feedbacksList.size());
    return dtoPage;
  }
  
  /**
   * 获取用户已发布的反馈.
   *
   */
  @Override
  public Page<Feedback> getMyFeedback(int page, int pageSize) {
    Page<Feedback> dtoPage = new Page<>(page, pageSize);
    
    // 获取当前用户id
    Long currentId = FeedbackServiceImpl.getUserId();
    
    LambdaQueryWrapper<Feedback> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Feedback::getUserId, currentId);
    queryWrapper.orderByDesc(Feedback::getCreateTime);
    List<Feedback> feedbacksList = this.list(queryWrapper);
    
    if (feedbacksList.size() == 0 || feedbacksList == null) {
      return dtoPage;
    }
    
    dtoPage.setRecords(feedbacksList);
    dtoPage.setTotal(feedbacksList.size());
    return dtoPage;
  }
  
  /**
   * 用户获取已处理的反馈.
   *
   */
  @Override
  public Page<Feedback> getPageFinish(int page, int pageSize) {
    Page<Feedback> dtoPage = new Page<>(page, pageSize);
    
    // 获取当前用户id
    Long currentId = FeedbackServiceImpl.getUserId();
    
    LambdaQueryWrapper<Feedback> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Feedback::getUserId, currentId);
    queryWrapper.eq(Feedback::getStatus2, 1);
    queryWrapper.eq(Feedback::getStatus1, 1);
    queryWrapper.orderByDesc(Feedback::getCreateTime);
    List<Feedback> feedbacksList = this.list(queryWrapper);
    
    if (feedbacksList.size() == 0 || feedbacksList == null) {
      return dtoPage;
    }
    
    dtoPage.setRecords(feedbacksList);
    dtoPage.setTotal(feedbacksList.size());
    return dtoPage;
    
  }
  
  
}
